package cn.zz.veggie.application.assembler;

import cn.hutool.core.util.StrUtil;
import cn.zz.comm.util.DateTimeUtil;
import cn.zz.veggie.model.domain.Settle;
import cn.zz.veggie.model.enums.CommStatus;
import cn.zz.veggie.model.query.SettleQuery;
import cn.zz.veggie.web.types.dto.mgmt.settle.MgmtSettleQueryDto;

/**
 * @author zhongq
 * @since 2024/6/7
 */
public class SettleAssembler {

	public static SettleQuery buildAdminQuery(MgmtSettleQueryDto dto) {
		final SettleQuery query = new SettleQuery();
		query.setUid(dto.getUid());
		query.setStatTimeStart(dto.getStatTimeStart());
		query.setStatTimeEnd(dto.getStatTimeEnd());
		return query;
	}

	public static Settle createSettle(Integer shopId, long timeStart, long timeEnd) {
		Settle settle = new Settle();
		settle.setShopId(shopId);
		settle.setOrderCount(0);
		settle.setAmount(0);
		settle.putStatus(CommStatus.active);
		settle.setStatTime(timeStart);
		settle.setStatTimeEnd(timeEnd);
		settle.setRemark(StrUtil.EMPTY);
		return settle;
	}

	public static void updateSettle(Settle settle, int orders, int totalAmount){
		settle.setOrderCount(orders);
		settle.setAmount(totalAmount);
	}

	public static Settle createSettle(Integer shopId, int orders, int totalAmount, long timeStart, long timeEnd) {
		Settle settle = new Settle();
		settle.setShopId(shopId);
		settle.setOrderCount(orders);
		settle.setAmount(totalAmount);
		settle.setStatus(0);
		settle.setStatTime(timeStart);
		settle.setStatTimeEnd(timeEnd);
		settle.setRemark(StrUtil.EMPTY);
		return settle;
	}

	public static void markComplete(Settle settle) {
		settle.putStatus(CommStatus.active);
		settle.setUpdatedAt(DateTimeUtil.unixTime());
	}
}